<template>
  <el-dialog class="clash-validate-panel" :visible="visible" :modal="false" append-to-body @close="close">
    <div slot="title" style="font-weight: bold">问题检测</div>
    <el-scrollbar class="content" ref="scrollBar">
      <div class="top-title">
        <div class="info-btn" :class="`${showType === 'error'}`" @click="changeType('error')">
          <div class="type-icon">
            <svg-icon icon-class="error" className='icon-clash'/>
          </div>
          <div class="type-txt">错误</div>
          <div class="type-num">{{ errorList.length }}</div>
        </div>
        <div class="info-btn" :class="`${showType === 'warning'}`" @click="changeType('warning')">
          <div class="type-icon">
            <svg-icon icon-class="warning" className='icon-clash warning'/>
          </div>
          <div class="type-txt">风险</div>
          <div class="type-num">{{ warningList.length }}</div>
        </div>
      </div>
      <div v-if="showType === 'error'" class="err-list">
        <div v-for="(item, index) in errorList" :key="item.msg" class="err-item">
          <span class="err-index">{{ index + 1 }}</span>
          <span v-if="item.node" @click="editNode(item.node)" class="err-node">【{{ item.node.data.name }}】</span>
          <span class="err-txt">{{ item.msg }}</span>
          <span v-if="item.node" class="err-btn" @click="editNode(item.node)">编辑</span>
        </div>
      </div>
      <div v-if="showType === 'warning'" class="err-list">
        <div v-for="(item, index) in warningList" :key="item.msg" class="err-item">
          <span class="err-index">{{ index + 1 }}</span>
          <span v-if="item.node" @click="editNode(item.node)" class="err-node">【{{ item.node.data.name }}】</span>
          <span class="err-txt">{{ item.msg }}</span>
          <span v-if="item.node" class="err-btn" @click="editNode(item.node)">编辑</span>
        </div>
      </div>
    </el-scrollbar>
  </el-dialog>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      showType: 'error'
    }
  },
  props: {
    visible: {
      type: Boolean
    }
  },
  computed: {
    ...mapState({
      clashList: state => state.clash.clashList
    }),
    errorList() {
      return this.clashList.filter(item => item.type === 'error')
    },
    warningList() {
      return this.clashList.filter(item => item.type === 'warning')
    }
  },
  watch: {
  },
  methods: {
    changeType(val) {
      this.showType = val
    },
    editNode(node) {
      this.$store.commit('graph/selectedItem', { type: 'node', data: node })
    },
    close() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss">
.clash-validate-panel {
  .el-dialog {
    position: absolute;
    top: 16px;
    left: auto;
    right: 16px;
    width: 500px;
    transform: none;
    margin: auto!important;
  }
  .el-dialog__body {
    padding: 0;
    overflow: hidden;
  }
  .content {
    height: 400px;
    .top-title{
      display: flex;
      width: 250px;
      height: 40px;
      margin: 9px auto;
      padding: 3px;
      border-radius: 20px;
      background-color: #f2f3f5;
      .info-btn{
        padding: 0 18px;
        border-radius: 20px;
        width: 122px;
        height: 34px;
        display: flex;
        align-items: center;
        .type-icon{
          margin: 0 5px 0 0;
          font-size: 16px;
          .icon-clash{
            color: #e6534e;
            &.warning{
              color: #F5AA14;
            }
          }
        }
        .type-txt{
          line-height: 18px;
        }
        .type-num{
          flex: 1;
          text-align: right;
        }
        &.true{
          background-color: #fff;
        }
      }
    }
    .err-list{
      border-top: 1px solid #e6e6e6;
      padding-bottom: 4px;
      .err-item{
        display: flex;
        align-items: center;
        height: 49px;
        border-bottom: 1px solid #e6e6e6;
        .err-index{
          width: 52px;
          text-align: center;
        }
        .err-node{
          color: #486cff;
          cursor: pointer;
        }
        .err-txt{
          flex: 1 0 200px;
        }
        .err-btn{
          color: #486cff;
          cursor: pointer;
          text-align: center;
          width: 100px;
        }
        &:nth-child(2n) {
          background-color: #f8f9fa;
        }
      }
    }
    .el-scrollbar__wrap {
      overflow-x: auto;
    }
  }
  .total-tag {
    display: inline-block;
    min-width: 24px;
    height: 18px;
    line-height: 18px;
    padding: 0 8px;
    margin-left: 8px;
    border-radius: 2px;
    background: #F5AA14;
    color: #fff;
    font-size: 12px;
    font-weight: normal;
    vertical-align: text-top;
    &.error {
      background: #e6534e;
    }
  }
}
.clash-validate-panel.el-dialog__wrapper {
  left: 296px;
  top: 60px;
}
</style>
